package com.bub.pay.core.manager.system.impl;

import com.bub.pay.core.dao.SysKvPairEntryDao;
import com.bub.pay.core.entity.domain.SysKvPairEntry;
import com.bub.pay.core.base.BaseManagerAbstract;
import com.bub.pay.core.enums.DeleteFlagEnum;
import com.bub.pay.core.manager.system.SysKvPairEntryManager;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

@Service
public class SysKvPairEntryManagerImpl extends BaseManagerAbstract<SysKvPairEntry, SysKvPairEntryDao> implements SysKvPairEntryManager {

    @Override
    public String getValue(String sysKey) {
        Example switchExample = new Example(SysKvPairEntry.class);
        switchExample.createCriteria().andEqualTo("baseKey", sysKey).andEqualTo("delFlag", DeleteFlagEnum.using.flag);
        SysKvPairEntry sysKvPairEntry = this.getOneByExample(switchExample);
        if(sysKvPairEntry == null){
            return null;
        }
        return sysKvPairEntry.getBaseValue();
    }

    @Override
    public Integer getIntValue(String sysKey) {
        String value = getValue(sysKey);
        if (StringUtils.isBlank(value)) {
            return null;
        }
        return Integer.valueOf(value);
    }

}
